package com.example.androidcoursedesign.login;

import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.androidcoursedesign.R;
import com.example.androidcoursedesign.login.utils.Utils;


public class RegisterAct extends AppCompatActivity implements View.OnClickListener {
    private ImageView registeractivity_back;
    private   EditText et_registeractivity_username;
    private   EditText et_registeractivity_password1;
    private   EditText et_registeractivity_password2;
    private   EditText et_registeractivity_phone;
    private   EditText et_registeractivity_email;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        registeractivity_back = findViewById(R.id.iv_registeractivity_back);
        Button bt_registeractivity_register = findViewById(R.id.bt_registeractivity_register);
        et_registeractivity_username = findViewById(R.id.et_registeractivity_username);
         et_registeractivity_password1 = findViewById(R.id.et_registeractivity_password1);
         et_registeractivity_password2 = findViewById(R.id.et_registeractivity_password2);
          et_registeractivity_phone = findViewById(R.id.et_registeractivity_phone);
        et_registeractivity_email = findViewById(R.id.et_registeractivity_email);
        registeractivity_back.setOnClickListener(this);
        bt_registeractivity_register.setOnClickListener(this);



    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.iv_registeractivity_back:
                //点击返回关闭当前界面
                RegisterAct.this.finish();
                break;
            case R.id.bt_registeractivity_register:
                String username = et_registeractivity_username.getText().toString();
                String email = et_registeractivity_email.getText().toString();
                String phone = et_registeractivity_phone.getText().toString();
                String password1 = et_registeractivity_password1.getText().toString();
                String password2 = et_registeractivity_password2.getText().toString();
                //校验输入值
                if (!password1.equals(password2)){
                    Toast.makeText(RegisterAct.this, "请确认密码是否一致", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (!Utils.checkEmail(email)){
                    Toast.makeText(this, "请输入正确的邮箱地址", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (!Utils.isMobile(phone)){
                    Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
                    return;
                }

                UserBean userBean = new UserBean();
                userBean.setUsername(username);
                userBean.setEmail(email);
                userBean.setPhone(phone);
                userBean.setPassword(password1);
                //实现注册



                break;
        }

    }
}
